# 9. 回文数
var isPalindrome = function(x) {
if (x < 0) return false;
flag = true;
const str = x + "";
for (let i = str.length - 1; i > 0; i--) {
if (str[i] !== str[str.length - 1 - i]) {
flag = false;
break;
}
}
return flag;
};
console.log(isPalindrome(121));
console.log(isPalindrome(-121));
console.log(isPalindrome(10));
console.log(isPalindrome(10101));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
← 876. 链表的中间结点 90. 子集2 →